package news.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import news.entity.Admin;
import news.service.AdminService;
import news.service.impl.AdminServiceImpl;

public class AdminServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		AdminService as = new AdminServiceImpl();
		HttpSession session = request.getSession();
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
//		PrintWriter out = response.getWriter();
		String uname = request.getParameter("uname");
		String upwd = request.getParameter("upwd");
		
		if(as.login(new Admin(uname,upwd))){
			response.sendRedirect("AuthorServlet?opr=findAllAuthor");
		}else{
			session.setAttribute("loginError", "loginError");
			response.sendRedirect("index.jsp");
		}
		
		
	}

}
